package client

import (
	"github.com/gin-gonic/gin"
	"likeadmin/admin/schemas/req"
	"likeadmin/admin/service/client"
	"likeadmin/core"
	"likeadmin/core/request"
	"likeadmin/core/response"
	"likeadmin/middleware"
	"likeadmin/util"
)

var RecordsGroup = core.Group("/client", newRecordsHandler, regRecords, middleware.TokenAuth())

func newRecordsHandler(srv client.IReadRecordsService) *recordsHandler {
	return &recordsHandler{srv: srv}
}

func regRecords(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *recordsHandler) {
		rg.GET("/read_records/list", handle.list)
	})
}

type recordsHandler struct {
	srv client.IReadRecordsService
}

// list records列表
func (hd recordsHandler) list(c *gin.Context) {
	var page request.PageReq
	var listReq req.ReadRecordsListReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
		return
	}
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
		return
	}
	res, err := hd.srv.List(page, listReq)
	response.CheckAndRespWithData(c, res, err)
}
